package com.example.study.config;

import com.github.pagehelper.PageInterceptor;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @Author 宋伟宁
 * @Date 2023/10/8
 * @Version 1.0
 **/
public class MyBatisConfig {

    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(@Autowired DataSource ds){
       SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
       //注入数据源
       sessionFactoryBean.setDataSource(ds);
       //创建分页对象
       sessionFactoryBean.setPlugins(new PageInterceptor());
       return  sessionFactoryBean;
    }
}
